package cn.xutongxue.book_sales.controller;


import cn.xutongxue.book_sales.base.Result;
import cn.xutongxue.book_sales.entity.Admin;
import cn.xutongxue.book_sales.service.AdminService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @author XuTongXue
 * @since 2021-12-02
 */
@RestController
@RequestMapping("/admin")
public class AdminController {

    @Resource
    private AdminService adminService;

    @PostMapping("/login")
    public Result login(@RequestBody Admin admin) {

        QueryWrapper<Admin> wrapper = new QueryWrapper<>();
        wrapper
                .eq("admin_name",admin.getAdminName());
        Admin user = new Admin();
        user = adminService.getOne(wrapper);
        if(user.getAdminName().equals(admin.getAdminName()) && user.getAdminPwd().equals(admin.getAdminPwd())) {
            return Result.ok("登录成功");
        } else {
            return Result.fail(801, "账号密码错误");
        }

    }


}
